home *** CD-ROM | disk | FTP | other *** search
- /* Dieses Programm wird von »Init« aufgerufen
- * (nur ab OS 2.0).
- * Autor: Rainer Zeitler
- */
- #include <exec/types.h>
- #include <exec/ports.h>
- #include <exec/semaphores.h>
-
- char *SemName="mysema"; /* Name der Semaphore */
-
- struct MyMessage {
- struct Message msg;
- struct MsgPort *ReplyPort;
- ULONG *change; /* Diese Variable ändern */
- } MsgSend, *MsgReceived;
-
- struct MsgPort *TestPort, *ReplyPort;
- struct SignalSemaphore *mysema;
-
- main() {
- ULONG count=0,*change;
- if( (TestPort=(struct MsgPort *)
- FindPort("Test-Semaphore")) != NULL ) {
- mysema=FindSemaphore(SemName);
- ReplyPort= CreatePort(0,0);
- MsgSend.msg.mn_Length=sizeof(struct MyMessage);
- MsgSend.msg.mn_Node.ln_Type=NT_MESSAGE;
- MsgSend.msg.mn_ReplyPort=NULL;
- MsgSend.ReplyPort=ReplyPort;
- /* Init mitteilen, daß wir bereit sind */
- PutMsg(TestPort,&MsgSend);
- /* Auf die Message von Init warten */
- WaitPort( ReplyPort );
- MsgReceived=GetMsg( ReplyPort );
- /* Diesen Speicherbereich modifizieren */
- change=MsgReceived->change;
- /* Semaphore reservieren */
- ObtainSemaphore(mysema);
- PutMsg(TestPort,&MsgSend);
- while( count < 1000000 )
- { *change+=1; count++; }
- /* Und wieder freigeben */
- ReleaseSemaphore(mysema);
- }
- }
-